from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-27 14:05:54.481893
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 27, Jan, 2022
Time: 14:05:59
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8628
Nobs: 549.000 HQIC: -48.2931
Log likelihood: 6411.23 FPE: 8.06749e-22
AIC: -48.5691 Det(Omega_mle): 6.85777e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351627 0.069904 5.030 0.000
L1.Burgenland 0.104921 0.042516 2.468 0.014
L1.Kärnten -0.111432 0.022036 -5.057 0.000
L1.Niederösterreich 0.195552 0.088722 2.204 0.028
L1.Oberösterreich 0.131895 0.087662 1.505 0.132
L1.Salzburg 0.255616 0.044865 5.697 0.000
L1.Steiermark 0.033129 0.059201 0.560 0.576
L1.Tirol 0.099760 0.047757 2.089 0.037
L1.Vorarlberg -0.072355 0.042206 -1.714 0.086
L1.Wien 0.018508 0.078051 0.237 0.813
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056807 0.151682 0.375 0.708
L1.Burgenland -0.041702 0.092254 -0.452 0.651
L1.Kärnten 0.040796 0.047815 0.853 0.394
L1.Niederösterreich -0.203909 0.192515 -1.059 0.290
L1.Oberösterreich 0.455556 0.190215 2.395 0.017
L1.Salzburg 0.283153 0.097352 2.909 0.004
L1.Steiermark 0.115310 0.128458 0.898 0.369
L1.Tirol 0.305589 0.103627 2.949 0.003
L1.Vorarlberg 0.023314 0.091582 0.255 0.799
L1.Wien -0.025362 0.169362 -0.150 0.881
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195398 0.035570 5.493 0.000
L1.Burgenland 0.091352 0.021634 4.223 0.000
L1.Kärnten -0.007337 0.011213 -0.654 0.513
L1.Niederösterreich 0.235830 0.045145 5.224 0.000
L1.Oberösterreich 0.168129 0.044606 3.769 0.000
L1.Salzburg 0.038388 0.022829 1.682 0.093
L1.Steiermark 0.025763 0.030123 0.855 0.392
L1.Tirol 0.080904 0.024301 3.329 0.001
L1.Vorarlberg 0.055351 0.021476 2.577 0.010
L1.Wien 0.117964 0.039715 2.970 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118094 0.035730 3.305 0.001
L1.Burgenland 0.043955 0.021731 2.023 0.043
L1.Kärnten -0.014031 0.011263 -1.246 0.213
L1.Niederösterreich 0.172339 0.045348 3.800 0.000
L1.Oberösterreich 0.335111 0.044806 7.479 0.000
L1.Salzburg 0.100016 0.022932 4.361 0.000
L1.Steiermark 0.109030 0.030259 3.603 0.000
L1.Tirol 0.091068 0.024410 3.731 0.000
L1.Vorarlberg 0.060077 0.021573 2.785 0.005
L1.Wien -0.015953 0.039894 -0.400 0.689
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124382 0.067434 1.845 0.065
L1.Burgenland -0.046393 0.041014 -1.131 0.258
L1.Kärnten -0.045487 0.021257 -2.140 0.032
L1.Niederösterreich 0.141028 0.085587 1.648 0.099
L1.Oberösterreich 0.167825 0.084565 1.985 0.047
L1.Salzburg 0.283254 0.043280 6.545 0.000
L1.Steiermark 0.059692 0.057109 1.045 0.296
L1.Tirol 0.154881 0.046070 3.362 0.001
L1.Vorarlberg 0.093326 0.040715 2.292 0.022
L1.Wien 0.071039 0.075294 0.943 0.345
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.082534 0.052527 1.571 0.116
L1.Burgenland 0.022173 0.031947 0.694 0.488
L1.Kärnten 0.053197 0.016558 3.213 0.001
L1.Niederösterreich 0.191667 0.066667 2.875 0.004
L1.Oberösterreich 0.328993 0.065871 4.995 0.000
L1.Salzburg 0.034566 0.033713 1.025 0.305
L1.Steiermark 0.002105 0.044485 0.047 0.962
L1.Tirol 0.120637 0.035886 3.362 0.001
L1.Vorarlberg 0.066326 0.031715 2.091 0.036
L1.Wien 0.099485 0.058649 1.696 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173238 0.063546 2.726 0.006
L1.Burgenland 0.006409 0.038650 0.166 0.868
L1.Kärnten -0.065532 0.020032 -3.271 0.001
L1.Niederösterreich -0.109381 0.080653 -1.356 0.175
L1.Oberösterreich 0.214574 0.079690 2.693 0.007
L1.Salzburg 0.052596 0.040785 1.290 0.197
L1.Steiermark 0.251429 0.053817 4.672 0.000
L1.Tirol 0.498054 0.043414 11.472 0.000
L1.Vorarlberg 0.063882 0.038368 1.665 0.096
L1.Wien -0.081514 0.070953 -1.149 0.251
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158680 0.070342 2.256 0.024
L1.Burgenland -0.005347 0.042783 -0.125 0.901
L1.Kärnten 0.062051 0.022174 2.798 0.005
L1.Niederösterreich 0.179558 0.089279 2.011 0.044
L1.Oberösterreich -0.067429 0.088212 -0.764 0.445
L1.Salzburg 0.206219 0.045147 4.568 0.000
L1.Steiermark 0.138335 0.059572 2.322 0.020
L1.Tirol 0.056779 0.048057 1.181 0.237
L1.Vorarlberg 0.143325 0.042471 3.375 0.001
L1.Wien 0.131077 0.078541 1.669 0.095
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394826 0.041033 9.622 0.000
L1.Burgenland -0.002174 0.024956 -0.087 0.931
L1.Kärnten -0.020611 0.012935 -1.593 0.111
L1.Niederösterreich 0.203026 0.052079 3.898 0.000
L1.Oberösterreich 0.241378 0.051456 4.691 0.000
L1.Salzburg 0.033409 0.026335 1.269 0.205
L1.Steiermark -0.017563 0.034750 -0.505 0.613
L1.Tirol 0.086733 0.028033 3.094 0.002
L1.Vorarlberg 0.050839 0.024775 2.052 0.040
L1.Wien 0.033865 0.045815 0.739 0.460
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035081 0.101743 0.165563 0.133955 0.091951 0.079978 0.028616 0.212619
Kärnten 0.035081 1.000000 -0.025677 0.133547 0.046738 0.085605 0.444725 -0.068888 0.093337
Niederösterreich 0.101743 -0.025677 1.000000 0.309700 0.124620 0.268253 0.066643 0.157048 0.282012
Oberösterreich 0.165563 0.133547 0.309700 1.000000 0.214704 0.293449 0.169949 0.135451 0.236359
Salzburg 0.133955 0.046738 0.124620 0.214704 1.000000 0.125590 0.088802 0.104606 0.126636
Steiermark 0.091951 0.085605 0.268253 0.293449 0.125590 1.000000 0.135672 0.104431 0.030522
Tirol 0.079978 0.444725 0.066643 0.169949 0.088802 0.135672 1.000000 0.065131 0.151052
Vorarlberg 0.028616 -0.068888 0.157048 0.135451 0.104606 0.104431 0.065131 1.000000 -0.004397
Wien 0.212619 0.093337 0.282012 0.236359 0.126636 0.030522 0.151052 -0.004397 1.000000